extends Node

var base
var Shop
var Dates = []#日期
var Workingday = [1,2,3,4,5]#周一至周五
var Restday = [0,6]#周日、周六
var HolidayTrue = false#节假日道具判定
var WorkingTrue = false#工作日功能判定
var Festival = {"情人节":[2,14],"愚人节":[4,1],"儿童节":[6,1],"七夕节":[8,14]}# 节日
var Holiday = {"元旦":[1,1],"劳动节":[5,1],"端午节":[6,14],"中秋节":[9,21],"国庆节":[10,1]}#假日

func _init():
	call_deferred("Init")

func Init():
	if globalData.infoDs.has("g_ZHPBase"):
		base = globalData.infoDs["g_ZHPBase"]
	if base != null:
		Shop = globalData.infoDs["g_ZHPShop"]
		base.connect("onSaveGame",self,"BickGame")
		base.connect("onExitGame",self,"BickGame")
		base.connect("onNewGame",self,"NewGame")
		Check()

func Check():
	checkWorkingday()
	checkRestday()
	checkDates()

var HolidayItem = ["i_Hide-ZHP-wuzhongshengyouGM","i_Hide-ZHP-CEGM","i_Hide-ZHP-ronghejiechuGM"]
func NewGame():
	yield(sys.get_tree().create_timer(0.5), "timeout")
	if HolidayTrue:
		for i in HolidayItem:
			sys.main.player.addItem(sys.newItem(i))

func checkWorkingday():#检查是否工作日
	for i in Workingday:
		if OS.get_date().get("weekday") == i:
			WorkingTrue = true
			break

func checkRestday():#检查是否休息日
	for i in Restday:
		if OS.get_date().get("weekday") == i:
			Shop.RestTime = 0.5
			break

func checkDates():#检查是否节假日
	Dates.append(OS.get_date().get("month"))
	Dates.append(OS.get_date().get("day"))
	for key in Festival.keys():
		if Dates == Festival.get(key):
			Shop.HoliTime = 1
			HolidayTrue = true
			break
	for key in Holiday.keys():
		if Dates == Holiday.get(key):
			Shop.HoliTime = 3
			HolidayTrue = true
			break

func BickGame():
	HolidayTrue = false
	Dates.clear()
	checkRestday()
	checkDates()